<?php
namespace dingtalk;

use dingtalk\util\Http;

class Chat
{

    /**
     * 创建会话
     * @param $accessToken
     * @param $chat
     * @return mixed
     */
    public static function createChat($accessToken,$chat)
    {
        $response = Http::post("/chat/create", ["access_token" => $accessToken],json_encode($chat));
        return obj2array($response);
    }

    /**
     * 修改会话
     * @param $accessToken
     * @param $chat
     * @return mixed
     */
    public static function updateChat($accessToken,$chat)
    {
        $response = Http::post("/chat/update", ["access_token" => $accessToken],json_encode($chat));
        return obj2array($response);
    }

    /**
     * 获取会话
     * @param $accessToken
     * @param $chatId
     * @return mixed
     */
    public static function getChat($accessToken,$chatId)
    {
        $response = Http::get("/chat/get", ["access_token" => $accessToken,"chat_id"=>$chatId]);
        return obj2array($response);
    }

    /**
     * 发送群消息
     * @param $accessToken
     * @param $chat
     * @return mixed
     */
    public static function sentChat($accessToken,$chat)
    {
        $response = Http::post("/chat/send", ["access_token" => $accessToken],json_encode($chat));
        return obj2array($response);
    }
}